<?php namespace testsacvoyage\domain;

require_once 'sacvoyage/Object.php';
use \sacvoyage\Object;

require_once 'sacvoyage/domain/Property.php';
use \sacvoyage\domain\Property;

require_once 'sacvoyage/domain/Share.php';
use \sacvoyage\domain\Share;

require_once 'sacvoyage/domain/Domain.php';
use \sacvoyage\domain\Domain;

require_once 'sacvoyage/domain/User.php';
use \sacvoyage\domain\User;

require_once 'sacvoyage/storage/Database.php';
use \sacvoyage\storage\Database;


require_once 'AbstractTest.php';

class ShareTest extends AbstractTest {
	
	public function setUp() {
	
		$this->resetDatabase();
		
		$this->_property=new Property(
			new User(
				new Domain($this->getStorage()),
				'alex',
				new Database($this->getGateway(), 'alex')			
			),
			$this->getStorage()->getDatabase('alex')
		);
		
		$sys_shares=$this->_property->getCollection('sys.user.shares');
		$config=new Object(array(
			'_id'=>"alexpublic",
			'permissions'=>new Object(array('db.notes'=>'full'))
		));
		$sys_shares->write(array($config));
		
		$this->_share=new Share($this->_property, $config);
		
	}
	
	public function testWriteRead() {
		$ownCollection=$this->_property->getCollection('db.notes');
		$ownCollection->write(array(new Object(array(
			'_id'=>'newnote', 
			'text'=>'note text'
		))));
		$sharedCollection=$this->_share->getCollection('db.notes');
		$doc=$sharedCollection->read('newnote');
		$this->assertEquals('note text', $doc->text);
	}
	
	
	
	
	
}



?>